﻿using System.Collections.Specialized;
using Newtonsoft.Json;

namespace CometDocs
{
    internal partial class Client
    {
        /// <summary>
        /// Invalidate an authentication token so that it can't be used anymore for future requests: https://www.cometdocs.com/developer/apiDocumentation#method-invalidateToken
        /// </summary>
        /// <param name="token">A valid authentication token.</param>
        public void InvalidateToken(AuthenticationToken token)
        {
            NameValueCollection @params = new NameValueCollection(1);
            @params.Add("token", token.Value);

            byte[] result = webClient.UploadValues(APIRoot + "invalidateToken", @params);

            string json = encoding.GetString(result);

            Response response = JsonConvert.DeserializeObject<Response>(json);

            CheckAndThrow(response);
        }
    }
}
